﻿namespace Simple.Common.Application.Dtos
{
    /// <summary>
    /// 返回对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ResultDto<T>
    {
        private bool? _isSuccess;
        /// <summary>
        /// 是否成功--默认为false
        /// </summary>
        public bool IsSuccess
        {
            get
            {
                if (_isSuccess.HasValue)
                {
                    return _isSuccess.Value;
                }

                var flag = true;
                switch (Data)
                {
                    case int intData when intData < 0:
                    case bool boolData when !boolData:
                    case null:
                    case string stringData when string.IsNullOrEmpty(stringData):
                        flag = false;
                        break;
                }
                _isSuccess = flag;
                return _isSuccess.Value;
            }
            set => _isSuccess = value;
        }
        /// <summary>
        /// 错误代码
        /// </summary>
        public int ErrorCode { get; set; }
        /// <summary>
        /// 返回消息
        /// </summary>
        public string Msg { get; set; }
        /// <summary>
        /// 返回的数据
        /// </summary>
        public T Data { get; set; }
        /// <summary>
        /// 返回的结果总数
        /// </summary>
        public int Count { get; set; }
    }
}
